﻿using System;
using System.ComponentModel;

namespace OpenLightGroup.Common
{
    /// <summary>
    /// Class that holds the static extension methods for EventHandlers
    /// </summary>
    public static class EventExtensions
    {
        /// <summary>
        /// Raises this event on the current object.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="sender">this object</param>
        /// <param name="propertyName">Name of the property that has changed</param>
        public static void Raise(this PropertyChangedEventHandler handler, object sender, string propertyName)
        {
            PropertyChangedEventArgs args = new PropertyChangedEventArgs(propertyName);

            if (handler != null)
                handler.Invoke(sender, args);
        }

        /// <summary>
        /// Raises this event on the current object, uses EventArgs.Empty.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="sender">this object</param>
        public static void Raise(this EventHandler handler, object sender)
        {
             Raise(handler, sender, EventArgs.Empty);
        }

        /// <summary>
        /// Raises this event on the current object.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="sender">this object</param>
        /// <param name="args">The argument to pass to the event.</param>
        public static void Raise(this EventHandler handler, object sender, EventArgs args)
        {
            if (handler != null)
                handler.Invoke(sender, args);
        }
    }
}
